/**
 * 存储登录相关用户数据
 */
import {
	loginApi
} from '@/apis/login.js'
import {
	log
} from 'util'
// 本地存储属性名
const user_key = 'zh-user'
const user = {
	namespaced: true,
	state: {
		// 用户信息（登录成功存储）
		userInfo: uni.getStorageSync('userInfo') || {
			token: '',
			userId: null
		}
	},
	mutations: {
		getUserInfo(state, newUserInfo) {
			state.userInfo = newUserInfo
			uni.setStorageSync('userInfo', newUserInfo)
		},
		delToken(state) {
			state.userInfo = {
				token: '',
				userId: null
			}
			uni.removeStorageSync('userInfo')
		}
	},
	actions: {
		async getLoginApi(store, formData) {
			// console.log(formData);
			let res = await loginApi(formData)
			store.commit('getUserInfo', res.data)
			return res
		}		
	}
}

export default user